//
//  ZYCMessageRootCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/16.
//

#import "ZYCMessageRootCell.h"
#import "LLBadgeButton.h"
#import "ZYCMessageRootModel.h"

@interface ZYCMessageRootCell()

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) LLBadgeButton *badgeButton;
@property (nonatomic, strong) UIView *redPoint;

@end

@implementation ZYCMessageRootCell

#pragma mark - setters
- (void)setModel:(ZYCMessageRootModel *)model{
    _model = model;
    _titleLabel.text = model.msgTypeName;
    _contentLabel.text = model.msg;
    _timeLabel.text = model.timeMsg;
    _iconView.image = [UIImage imageNamed:model.imageName];
    ///1：通知；2：周历；3：行政值班；4：学生请假；5：评价评学；6：巡堂记录  7:考勤消息  8:审批消息
    NSInteger msgStatus = [model.msgStatus integerValue];
    if (msgStatus == 1) {//未阅读
        if ([model.msgType integerValue] == 3 || [model.msgType integerValue] == 6 || [model.msgType integerValue] == 7) {
            _redPoint.hidden = YES;
            _badgeButton.hidden = NO;
            _badgeButton.badgeValue = [model.msgCount integerValue];
        }else{
            _redPoint.hidden = NO;
            _badgeButton.hidden = YES;
        }
    }else {// 已阅读
        _redPoint.hidden = YES;
        _badgeButton.hidden = YES;
    }
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.iconView];
        [self.iconView addSubview:self.redPoint];
        [self.iconView addSubview:self.badgeButton];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.timeLabel];
        [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(16.5);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(55, 55));
        }];
        
        [self.redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.iconView).offset(-5.0f);
            make.top.equalTo(self.iconView).offset(5.0f);
            make.size.mas_equalTo(CGSizeMake(10, 10));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(6.5);
            make.top.equalTo(self.iconView).offset(7);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(6.5);
            make.bottom.equalTo(self.iconView).offset(-5);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-20);
            make.centerY.equalTo(self.titleLabel);
        }];
    }
    return self;
}


#pragma mark - getters
- (UIImageView *)iconView {
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

- (UIView *)redPoint {
    if (!_redPoint) {
        _redPoint = [[UIView alloc] init];
        _redPoint.layer.cornerRadius = 5.0f;
        _redPoint.layer.masksToBounds = YES;
        _redPoint.backgroundColor = [UIColor redColor];
    }
    return _redPoint;
}


- (UILabel *)titleLabel {
    if (!_titleLabel) {        
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleBlackColor) textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(kTitleDarkGrayColor) textAlignment:ZZTextAlignmentLeft];
    }
    return _contentLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 13) titleColor:HEX_RGB(kTitleLightGrayColor) textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}


- (LLBadgeButton *)badgeButton {
    if (!_badgeButton) {
        _badgeButton = [[LLBadgeButton alloc] initWithFrame:CGRectMake(40, 10, 0, 0)];
    }
    return _badgeButton;
}



@end
